/**
 * 公告相关API
 */
import { apiClient, API_ENDPOINTS } from './index'
import type { ApiResponse } from './types/common'

// 定义公告列表项类型
export interface AnnouncementItem {
  id: number;
  title: string;
  brief: string;
  type: string;
  is_top: boolean;
  publish_time: string;
  view_count: number;
  admin_name: string;
  time: number;
}

// 定义公告详情类型
export interface AnnouncementDetail extends AnnouncementItem {
  content: string;
}

// 定义公告列表响应类型
export interface AnnouncementsResponse {
  total: number;
  list: AnnouncementItem[];
}

// 定义查询参数类型
export interface AnnouncementQueryParams {
  type?: string[];
  search?: string;
  start_time?: string;
  end_time?: string;
  sort?: 'newest' | 'oldest';
  page?: number;
  pageSize?: number;
}

/**
 * 获取公告列表
 * @param params 查询参数
 * @returns Promise
 */
export async function getAnnouncements(params?: AnnouncementQueryParams): Promise<ApiResponse<AnnouncementsResponse>> {
  return apiClient.get<AnnouncementsResponse>(API_ENDPOINTS.ANNOUNCEMENTS, { params });
}

/**
 * 获取公告详情
 * @param id 公告ID
 * @returns Promise
 */
export async function getAnnouncementDetail(id: number): Promise<ApiResponse<AnnouncementDetail>> {
  return apiClient.get<AnnouncementDetail>(API_ENDPOINTS.ANNOUNCEMENT_DETAIL, { params: { id } });
}